<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .item {
            width: 8em;
            height: 100px;
            background: gray;
        }

        .red {
            background: red !important;
        }
    </style>
</head>

<body>
    <div class="item red" style="background-color: green; width:auto">

    </div>

    <script>
        var div = document.querySelector(".item");
        //得到div最终计算的样式
        var style = getComputedStyle(div);
    </script>
</body>

</html>